diag_log "TEST:SAVE";

_saveId = param[0, "", [""]];
_container = param[1, objNull, [objNull]];

if((_saveId != "") && (!isNull _container)) then
{
	if(alive _container) then
	{
		if(!(_container isKindOf "Man")) then
		{
			_varName = format["gsave_%1", _saveId];
			_savedGears = profileNamespace getVariable["gsave_list", []];

			_cWeps = weaponsItemsCargo _container;
			_cMags = magazinesAmmoCargo _container;
			_cItems = itemCargo _container;
			_cContainers = [];

			{
				_cDescription = [];		
				_cRef = _x select 1;

				_scWeps = weaponsItemsCargo _cRef;
				_scMags = magazinesAmmoCargo _cRef;
				_scItems = itemCargo _cRef;

				_cDescription = [_x select 0, _scWeps, _scMags, _scItems];
				_cContainers pushBack _cDescription;

			} foreach (everyContainer _container);

			_cGear = [CONTAINER, _cWeps, _cMags, _cItems, _cContainers];

			if(!(_varName in _savedGears)) then
			{ _savedGears pushBack _varName; };

			profileNamespace setVariable["gsave_list", _savedGears];
			profileNamespace setVariable[_varName, _cGear];

			if(dnct_var_gsave_debug) then
			{ hint parseText format["<t align='left' size='1.2'>gSave: container save successful!</t><br/><br/><t align='left'>Container '%1' has been saved with an ID of '%2'.</t><br/><br/><t align='left' size='0.8' color='#808080'>This message is displayed only in debug mode.</t>", _container, _saveID]; };
		}
		else
		{
			if(dnct_var_gsave_debug) then
			{ hint parseText "<t align='left' size='1.2'>gSave Container Save Error</t><br/><br/><t align='left'>You are have tried to save unit's gear as container's preset. Please check your container's variable name.</t><br/><br/><t align='left' size='0.8' color='#808080'>This message is displayed only in debug mode.</t>"; };
		};
	}
	else
	{
		if(dnct_var_gsave_debug) then
		{ hint parseText "<t align='left' size='1.2'>gSave Container Save Error</t><br/><br/><t align='left'>You have tried to save content of a container that is destroyed. Destroyed containers have no content.</t><br/><br/><t align='left' size='0.8' color='#808080'>This message is displayed only in debug mode.</t>"; };
	};
}
else
{
	hint parseText format["<t align='left' size='1.2'>gSave Container Save Error</t><br/><br/><t align='left'>dnct_fnc_SaveContainer received an incorrect set of arguments (%1).<br/><br/>Please ensure that the first argument is string representig a certain save ID and the second argument is a valid container.<br/><br/><t align='left' size='0.8'>This message means that the gear cannot be properly saved due to error specified above. However, you still can try to complete this mission without your gear.</t>", str(_this)];
};